package br.elsa.survey.dao;

import java.util.List;

import javax.ejb.Stateful;
import javax.persistence.EntityManager;

import br.elsa.survey.dao.exceptions.DataNotFoundException;
import br.elsa.survey.domain.questions.CheckboxQuestion;
import br.elsa.survey.domain.questions.DiscursiveQuestion;
import br.elsa.survey.domain.questions.Question;
import br.elsa.survey.domain.questions.RadioQuestion;

/**
 * Component of Persistence Layer that implements DAO functionalities for
 * {@link Question} entities.
 * 
 * @author diego
 * @since 2010-10-22
 */
@Stateful
public class QuestionDao extends Dao<Question> {

	private static final long serialVersionUID = 5146997281055378780L;

	/**
	 * Default constructor.
	 */
	public QuestionDao() {

	}

	/**
	 * Constructor used by test classes to inject Mock dependencies
	 * 
	 * @param entityManager
	 *            Mock dependency
	 */
	public QuestionDao(EntityManager entityManager) {
		super(entityManager);
	}

	/**
	 * Counts the number of {@link CheckboxQuestion} exists in database
	 * 
	 * @return the {@link CheckboxQuestion} count
	 */
	public int checkboxQuestionsCount() {

		return count(CheckboxQuestion.class);
	}

	/**
	 * Counts the number of {@link RadioQuestion} exists in database
	 * 
	 * @return the {@link RadioQuestion} count
	 */
	public int radioQuestionsCount() {

		return count(RadioQuestion.class);
	}

	/**
	 * Counts the number of {@link DiscursiveQuestion} exists in database
	 * 
	 * @return the {@link DiscursiveQuestion} count
	 */
	public int discursiveQuestionsCount() {

		return count(DiscursiveQuestion.class);
	}

	/**
	 * Retrieves all registered {@link Question} in the database
	 * 
	 * @return {@link List} of all registered {@link Question} in the system
	 * @throws DataNotFoundException
	 *             Thrown if no data is found
	 */
	public List<Question> findAll() throws DataNotFoundException {

		return findAll(Question.class);
	}

}
